package com.x.Part9_objectArray;

import java.util.Random;

/**
 * ClassName: objectArrayTest
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2023/9/17 21:49
 */
public class objectArrayTest {
    public static void main(String[] args) {

        //对象数组
        //new一个Student[]类型的数组，数组元素是待实例化的对象
        Student[] stu1 = new Student[10];
        for(int i = 0; i < 10 ; i++){
            //十个对象的实例化
            stu1[i] = new Student();

            stu1[i].age = 20;
            stu1[i].id = 20230001 + i;
            stu1[i].score = Math.random() * 101;
        }

        //打印学号、成绩信息
        for(int i = 0; i < stu1.length; i++){

            if(i < stu1.length-1)
                System.out.print(stu1[i].getScore() + ", ");
            else
                System.out.println(stu1[i].getScore());
        }

        for(int i = 0; i < stu1.length; i++){

            if(i < stu1.length-1)
                System.out.print(stu1[i].getId() + ", ");
            else
                System.out.println(stu1[i].getId());
        }

        //输出分数大于80的学生学号
        for(int i = 0; i < stu1.length; i++){
            if(stu1[i].score >= 80)
                stu1[i].showId();
        }

    }
}
